package com.uphone.kingmall.adapter;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.china.zhuoyue.R;
import com.uphone.kingmall.bean.UserAddrBean;

/**
 * <pre>
 *     author : 王雨
 *     e-mail : sunzengyan@outlook.com
 *     time   : 2018/07/31
 *     desc   :
 *     version: 1.0
 * </pre>
 */
public class AddressListAdapter extends BaseQuickAdapter<UserAddrBean, BaseViewHolder> {
    private OnAddressItemClickListener listener;

    public AddressListAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(final BaseViewHolder helper, final UserAddrBean item) {
        helper.setText(R.id.tv_name, item.getReceiver() + "");
        helper.setText(R.id.tv_address, item.getRegion() + item.getAddress() + "");
        helper.setText(R.id.tv_phone, item.getTelephone() + "");
        if (item.getBlDefault() == 1) {
            helper.getView(R.id.tv_defualt).setVisibility(View.VISIBLE);
        } else {
            helper.getView(R.id.tv_defualt).setVisibility(View.GONE);
        }
        helper.getView(R.id.tv_edit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.editItem(v, helper.getLayoutPosition(), item);
                }
            }
        });
    }

    public void setOnAddressItemClickListener(OnAddressItemClickListener listener) {
        this.listener = listener;
    }

    public interface OnAddressItemClickListener {
        void editItem(View v, int position, UserAddrBean item);
    }
}
